﻿namespace MicroCloud.Message
{
    /// <summary>
    /// 消息模块
    /// </summary>
    [Description("消息模块")]
    [DependsOnPacks(typeof(SignalRPack), typeof(HangfirePack), typeof(IdentityPack))]
    public class MessagePack : AspPackBase
    {
        /// <summary>
        /// 获取 模块级别，级别越小越先启动
        /// </summary>
        public override PackLevel Level => PackLevel.Business;

        /// <summary>
        /// 获取 模块启动顺序编号，模块启动的顺序先按级别启动，同一级别内部再按此顺序启动，
        /// 级别默认为0，表示无依赖，需要在同级别有依赖顺序的时候，再重写为>0的顺序值
        /// </summary>
        public override int OrderNo => 0;

        /// <summary>
        /// 将模块服务添加到依赖注入服务容器中
        /// </summary>
        /// <param name="services">依赖注入服务容器</param>
        /// <returns></returns>
        public override IServiceCollection AddServices(IServiceCollection services)
        {
            services.AddScoped<IMessageService, MessageService>();

            //注册DTO对象映射
            services.AddSingleton<IMapTuple, AutoMapperMessageConfiguration>();

            //注册事件委托
            services.AddEventHandler<HubConnectionEventHandler>();
            services.AddEventHandler<MessageEventHandler>();
            services.AddEventHandler<TemplateMessageEventHandler>();
            services.AddEventHandler<MessageSendEventHandler>();
            services.AddEventHandler<MessageReadEventHandler>();

            return services;
        }

    }
}
